/*
 * Alloy Analyzer
 * Copyright (c) 2002 Massachusetts Institute of Technology
 *
 * The Alloy Analyzer is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The Alloy Analyzer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the Alloy Analyzer; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package alloy.gui;

import javax.swing.tree.DefaultMutableTreeNode;

import alloy.ast.LeafId;
import alloy.ast.Node;

/** Information about an AST {@link Node}, stored as the user object in the
    tree nodes of the Swing AST representation returned by {@link SwingASTVisitor}.
    @see SwingASTRenderer */
class NodeInfo {
    /** The AST {@link Node} represented by this Swing node. */
    private final Node _node;

    /** The quantified variables upon which this node depends. */
    private LeafId[] usedVarIds;

    /** The {@link String} label of the node. */
    private String _label;

    /** The tooltip text to display for this node. */
    private String _tooltip;

    /** Whether the node represents a false value that should be highlighted. */
    private boolean _isFalse;

    /** This is a node representing a true expression, or a quantified formula that
        is true for all combinations of its quantified variables. */
    private boolean _isTrue;

    /** If this node has a Swing value tree, _valueTree references it. */
    private DefaultMutableTreeNode _valueTree;

    /** indicates whether this node has had its value tree already computed. */
    private boolean _valueTreeComputed;

    /** indicates if this node was created as the result of a Node annotation */
    private boolean _isAnnotation;

    /** and if this node has an annotation */
    private boolean _hasAnnotation;

    /** Prepend given text to this node's label. */
    void prependToLabel(String text_) { _label = text_ + _label; }
    
    /** Append given text to this node's label. */
    void appendToLabel(String text_) { _label = _label + text_; }

    /** @return the AST {@link Node} represented by this Swing node. */
    Node getNode() { return _node; }

    /** Whether the node represents a false value that should be highlighted. */
    boolean isFalse() { return _isFalse; }

    /** Mark this as representing a false value. */
    void markFalse() { _isFalse = true; }

    /** Likewise, for true flags. */
    boolean isTrue() { return _isTrue; }

    void markTrue() { _isTrue = true; }

    /** returns the value tree, if any, associated with the node. */
    DefaultMutableTreeNode getValueTree () { return _valueTree; }

    /** sets the value tree */
    void setValueTree (DefaultMutableTreeNode valueTree_) {
	_valueTree = valueTree_;
    }

    void setUsedVarIds (LeafId[] usedVarIds_) {
	usedVarIds = usedVarIds_;
    }

    LeafId[] getUsedVarIds () {
	return usedVarIds;
    }

    boolean valueTreeComputed () {
	return _valueTreeComputed;
    }

    void setValueTreeComputed (boolean valueTreeComputed_) {
	_valueTreeComputed = valueTreeComputed_;
    }

    boolean isAnnotation () {
	return _isAnnotation;
    }

    void setIsAnnotation (boolean isAnnotation_) {
	_isAnnotation = isAnnotation_;
    }
    boolean hasAnnotation () {
	return _hasAnnotation;
    }

    void setHasAnnotation (boolean hasAnnotation_) {
	_hasAnnotation = hasAnnotation_;
    }

    NodeInfo(String label_) { this(label_, null); }
    NodeInfo(String label_, Node node_) {
	_label = label_; _node = node_;
	if (node_ != null) {
	    String transformAnnot = node_.getTransformAnnotation();
	    if (transformAnnot!=null && transformAnnot.trim().length() > 0)
		setToolTipText(transformAnnot);
	}
	_valueTree = null;
	_valueTreeComputed = false;
	_isAnnotation = false;
	_hasAnnotation = false;
    }

    void setToolTipText(String tooltip_) {
	_tooltip = tooltip_;
    }

    /** Return tooltip string to be displayed for this node. */
    String getToolTipText() { return _tooltip; }

    public String toString() { return _label; }
}
